package com.example.oauthserver.demo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * ClassName:UserDetailService
 *
 * @Author: Jameson Yang
 * @Description:
 * @Date: created in 16:34 08/27/19
 */
@Slf4j
@Service
public class UserDetailService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("=============================user name is:{}", username);
        if (username.equals("ygs")) {
            PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            String password = passwordEncoder.encode("123456");
            UserDetails userDetails = new User("ygs",
                password,
                AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
            return userDetails;
        }
        return null;
    }
}
